<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="hearder-search">
        <div class="toplineBox mb-10">
          <div class="toplineBox-left">
            <el-button size="small" @click="refreshFn"><i class="el-icon-refresh"></i>刷新</el-button>
            <el-button size="small" @click="gotoDetail()" type="primary"><i class="el-icon-plus"></i>添加仓库</el-button>
          </div>
          <p class="numberline toplineBox-right">总{{ page.total }}条</p>
        </div>
      </div>
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              style="width: 100%"
              header-cell-class-name="table-text-c"
              cell-class-name="table-text-c">
            <el-table-column
                prop="name"
                label="仓库名称">
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="创建时间">
            </el-table-column>
            <el-table-column
                label="操作"
                width="200">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="gotoDetail(scope.row.id)" plain>详情</el-button>
                <el-button size="small" @click="detelTearch(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <add_warehouse :visible.sync="warehouseVisible" :warehouseId="warehouseId" @InitFn="InitFn"></add_warehouse>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import add_warehouse from "./add_warehouse";

export default {
  components: {
    add_warehouse
  },
  data() {
    return {
      warehouseVisible: false,
      arryList: [], // 页面数据列表
      // 搜索设置
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      warehouseId: 0
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn() {
      this.$fetch(this.api.mater.warehouse.index, {
        p: this.page.pageindex
      }).then((response) => {
        if (response.code === 0) {
          this.arryList = response.list.data
          this.page.total = response.list.total
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.InitFn()
    },
    gotoDetail(id) {
      this.warehouseId = id || ''
      this.warehouseVisible = true
      // this.$router.push('classDetail?editId=' + editId)
    },
    detelTearch(index) {
      let name = this.arryList[index].name
      this.$confirm('确认永久删除 ' + name + ' 仓库信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(index)
      }).catch(() => {
      })
    },
    detelRespon(index) {
      let data_ = {}
      data_.id = this.arryList[index].id
      this.$post(this.api.mater.warehouse.delete, data_).then((response) => {
        if (response.code === 0) {
          this.InitFn()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  },
  // 缓存机制end
  mounted() {
  }
}
</script>
